define(function (require, exports, module) {
    var util = require('util');
    var ui = require('ui');
    var common = require('./common');
    var angular = require("angular");
    require("angular-route");
    require("angular-ui");
    require('authorize');
    require('service/ng_service/projectService');
    require('./project_reported_rules');
    require('./project_houses_param');
    require('./project_commission_rules');
    require('permission');

    angular.module('app', ['ngRoute', 'ngUI', 'ProjectReportedRules', 'ProjectHousesParam', 'ProjectCommissionRules'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider
                .when('/reported_rules', {templateUrl: 'inc/reported_rules.html'})
                .when('/houses_param', {templateUrl: 'inc/houses_param.html'})
                .when('/commission_rules', {templateUrl: 'inc/commission_rules.html'})
                .otherwise({redirectTo: '/reported_rules'});
        }])
        .controller('MainController', ['$rootScope', '$scope', '$location', '$routeParams', 'projectList',
            function ($rootScope, $scope, $location, $routeParams, projectList) {
                $scope.tabs = [
                    {value: '/reported_rules', name: '报备规则'},
                    {value: '/houses_param', name: '楼盘参数设置'},
                    {value: '/commission_rules', name: '佣金规则'}
                ];

                $scope.setTabSelected = function (tab) {
                    if (tab.value !== $location.path()) {
                        $location.url(tab.value);
                        $scope.current = $location.path();
                    }
                };

                projectList.then(
                    function (res) {
                        var projectList = res.data.data;

                        $scope.projectList = projectList;

                        $scope.current = $location.path();
                    }
                );
            }
        ]);

    angular.bootstrap(document, ['app']);
});